// 判断用户登录状态
let userInfo = '';
// 判断用户类型
function userType0() {
    if (JSON.parse(localStorage.user).enterType) {
        return 2; //平台商
    } else {
        return 1; //用户
    }
}
if (localStorage.token != null) {
    userInfo = JSON.parse(localStorage.user);
    // $(".user-btn").css("display","none") 
    $(".user-info .user-tip").html("Hi!" + "&nbsp" + userInfo.name);
    // $(".user-info .user-btn").css("display","none");
    $(".login-before").css("display", "none");
    $(".logined").css("display", "block");
    $(".login-name").html(userInfo.name);
    if (userInfo.enterType) { //判断是商户
        $(".login .glyphicon-user").click(function () {
            window.location.href = "business-vip.html"
        })
        // 商户中心跳转
        $(".login .login-name").click(function () {
            window.location.href = "business-vip.html";
        })
        $(".con li:lt(2)").click(function () {
            window.location.href = "business-vip.html";
        })
        // 首页商户头像
        console.log(userInfo.imgPath)
        if (userInfo.imgPath == '') {
            $(".page1 .user .user-info .user-img img").attr("src", '../img/132.png');
            $(".detail .content .page3-left .input-content .user-img img").attr("src", '../img/132.png');
        } else {
            $(".page1 .user .user-info .user-img img").attr("src", userInfo.imgPath);
            $(".detail .content .page3-left .input-content .user-img img").attr("src", userInfo.imgPath);
        }

    } else { //个人login-name
        $(".login .glyphicon-user").click(function () {
            window.location.href = "user-vip.html";
        })
        $(".login .login-name").click(function () {
            window.location.href = "user-vip.html";
        })
        $(".con li:lt(2)").click(function () {
            window.location.href = "user-vip.html";
        })

        // 首页个人头像
        $(".page1 .user .user-info .user-img img").attr("src", userInfo.imgUrl);
    }
} else {
    $(".login .glyphicon-user").click(function () {
        window.location.href = "login.html";
    })
}
// console.log(localStorage)
// 网址模拟下拉
$(".pt-info .icon-down").click(function () {
    $(".pt-info .area .area1").css("height", "auto")

})
$(".pt-info .area .area1").hover(function () {
    $(".pt-info .area .area1").css("height", "auto");
}, function () {
    $(".pt-info .area .area1").css("height", "24px");
})


// 左侧文字滚动，右侧轮播图片切换
$("#carousel-example-generic").on('slide.bs.carousel', function (obj) {
    // 当前轮播索引
    var index = $(this).find('.item').index(obj.relatedTarget);
    var imgIndex = $(".img-show a");
    // console.log(imgIndex)
    for (let i = 0; i < imgIndex.length; i++) {
        imgIndex.removeClass("active");
    }
    imgIndex.eq(index).addClass("active");
});
// 移动端折叠导航
$(".m-header .btn-burger").click(function () {
    // console.log($(this).attr('aria-expanded'))
    console.log($(".user-dropmenu").height())
    var drop_open = $(this).attr('aria-expanded');
    if ($(".user-dropmenu").height() == 0) {
        $(".user-dropmenu").css("height", "auto");
        $("body").addClass("hidden-scroll");
    } else {
        $(".user-dropmenu").css("height", "0px");
        $("body").removeClass("hidden-scroll");
    }
})

// 筛选-更多下拉.height()

$(".ele-box .more span").click(function () {
    console.log($(".ele-label form").height())
    if ($(".ele-label form").height() == 80) {
        $(".ele-label form").css("height", "auto");
    } else {
        alert(2222222)
        $(".ele-label form").css("height", "80px");
    }
})
//封装 ----获取url的参数id
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
    var context = "";
    if (r != null)
        context = r[2];
    reg = null;
    r = null;
    return context == null || context == "" || context == "undefined" ? "" : context;
}
// 获取时分秒
function getNowTime() {
    var date = new Date();
    this.year = date.getFullYear();
    this.month = date.getMonth() + 1;
    this.date = date.getDate();
    this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    var currentTime = this.year + '-' + this.month + '-' + this.date + ' ' + this.hour + ':' + this.minute + ':' + this.second;
    return currentTime;
}
//JS计算两个日期时间差，天 小时 分 秒格式
function diffTime(startDate, endDate) {

    startDate = new Date(startDate);

    endDate = new Date(endDate);

    var diff = endDate.getTime() - startDate.getTime(); //时间差的毫秒数 



    //计算出相差天数 

    var days = Math.floor(diff / (24 * 3600 * 1000));



    //计算出小时数 

    var leave1 = diff % (24 * 3600 * 1000); //计算天数后剩余的毫秒数 

    var hours = Math.floor(leave1 / (3600 * 1000));

    //计算相差分钟数 

    var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数 

    var minutes = Math.floor(leave2 / (60 * 1000));



    //计算相差秒数 

    var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数 

    var seconds = Math.round(leave3 / 1000);



    var returnStr = seconds + "秒";

    if (minutes > 0) {

        returnStr = minutes + "分";

    }

    if (hours > 0) {

        returnStr = hours + "小时";

    }

    if (days > 0) {

        returnStr = days + "天";

    }

    return returnStr;

}













// 全局搜索
$('#searchAll').click(function () {
    let sVal = $('#sInput').val(); //获取搜索框的内容
    if (sVal == "") {
        alert("搜索不能为空！")
        return false;
    }
    window.location.href = "search.html?keyword=" + sVal;
})



// 热门搜索标签
$(function () {    
        Getdata(getValueByName,{name: 'search_hot_class_tags'}).then(res => {
        // console.log(res)
        let tags = res.data.value.split('-');
        let tagItem = "";
        // console.log(tags)
        $.each(tags, function (index, val) {
            tagItem = "<span><a href=\"javaScript:;\">"+ val+ "</a></span>";
            $(".search").append(tagItem);
        })
        // $(".search span a")
    })


})



// 点发布限制
$("#pushBtn").click(function () {
    if (localStorage.token == null) {
        alert("请先登录！")
        window.location.href = "login.html";
    } else {
        window.location.href = "pushc.html";
    }
})


